package study.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "OneServlet",value = "/one")
public class OneServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

          request.setAttribute("one",10);

         HttpSession session = request.getSession();

         session.setAttribute("two",20);

         //request.getRequestDispatcher("/two").forward(request,response);

        //response.sendRedirect("two");

        //获得全局对象
        ServletContext servletContext = this.getServletContext();

        servletContext.setAttribute("context",30);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }
}
